home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / comtoi.pqs / comtoi.pas
Pascal/Delphi Source File  |  1985-06-03  |  4KB  |  132 lines

  1. program ComToInL;
  2.  
  3. { Program ComToInL by Michael Quinlan   12/17/84 } 
  4.  
  5. { Problem: 
  6.     Turbo Pascal is great BUT it still has some problem areas. One of these
  7.     is a bug having to do with EXTERNAL procedures -- if youcompile to disk, 
  8.     EXTERNAL procedures longer than 128 bytes don't work. You can get around 
  9.     this bug by compiling to memory first; unfortunately when you use 
  10.     overlays you cannot compile to memory so you are stuck. }
  11.  
  12. { The fix: 
  13.     Borland doesn't seem to be forthcoming with a patch or new release to fix 
  14.     this bug, so I have written this program to convert .COM files to INLINE 
  15.     code that you can include in your source program. This will greatly 
  16.     increase the compile time of your programs, but at least you won't have
  17.     completly wasted all that time writing and debugging your assembler 
  18.     program. } 
  19.  
  20. { The environment: 
  21.     I have used this on an IBM PC with Version 2.00B of Turbo Pascal for the
  22.     IBM PC I assume it will work on other MSDOS machines. I know nothing 
  23.     about CPM-80 or CPM-86 so I don't know what problems will be encountered
  24.     in those environments. 
  25.     This program has NOT been completely tested. I rarely need EXTERNAL 
  26.     routines when using Turbo Pascal and have only used this conversion 
  27.     program a couple of times. }
  28.  
  29. { Usage: 
  30.     First, create and debug your assembler language program. The assembler 
  31.       language program must be converted to a .COM file using EXE2BIN. 
  32.     Second, run ComToInL to convert the .COM file to a .PAS file.
  33.     Third, include the .PAS file created above into the source code of your
  34.       Turbo Pascal program. Example: 
  35.  
  36.         Overlay Procedure A; 
  37.        begin 
  38.         (*$IA.PAS*)  (* Include INLINE code generated from .COM file *) 
  39.         end; 
  40.         Overlay Procedure B; 
  41.         begin 
  42.         (*$IB.PAS*)  (* Include INLINE code generated from .COM file *) 
  43.         end; 
  44.  
  45. const 
  46.   MaxLineLength = 126; 
  47.  
  48. type 
  49.   Lstr = String[255]; 
  50.  
  51. var 
  52.   InFile      : File of Byte;
  53.   OutFile     : Text;
  54.   CharsOnLine : Integer; 
  55.   InFileName  : Lstr; 
  56.   OutFileName : Lstr; 
  57.   B           : Byte; 
  58.   C           : Char; 
  59.   D1, D2      : Integer; 
  60.  
  61. const 
  62.   HexTable : Array[0..15] of Char = '0123456789ABCDEF';
  63.  
  64. procedure StrToUpper(var S : Lstr); 
  65. var 
  66.   i : integer;
  67. begin 
  68.   for i := 1 to length(S) do 
  69.     S[i] := UpCase(S[i]) 
  70. end; 
  71.  
  72. procedure GetFileName(var FileName : Lstr; Ext : Lstr); 
  73. begin 
  74.   Readln(FileName); 
  75.   StrToUpper(FileName);
  76.   if pos('.', FileName) = 0 then FileName := FileName + Ext 
  77. end; 
  78.  
  79. procedure WriteLnOut; 
  80.   { used to end line on screen and file } 
  81. begin 
  82.   WriteLn(OutFile);
  83.   WriteLn; 
  84.   CharsOnLine := 0 
  85. end; 
  86.  
  87. procedure WriteOut(S : Lstr); 
  88.   { used to write data to screen and file at the same time }
  89. begin 
  90.   if (CharsOnLine + Length(S)) >= MaxLineLength then 
  91.     WriteLnOut; 
  92.   Write(OutFile, S); 
  93.   Write(S); 
  94.   CharsOnLine := CharsOnLine + Length(S) 
  95. end; 
  96.  
  97. begin
  98.   Write('Input file name: '); 
  99.   GetFileName(InFileName, '.COM'); 
  100.  
  101.   Write('Output file name: '); 
  102.   GetFileName(OutFileName, '.PAS'); 
  103.  
  104.   Assign(InFile, InFileName); 
  105.   Reset(InFile); 
  106.  
  107.   Assign(OutFile, OutFileName); 
  108.   Rewrite(OutFile); 
  109.  
  110.   CharsOnLine := 0;
  111.  
  112.   WriteOut('{ INLINE Code Generated from ' + OutFileName + ' }'); 
  113.   WriteLnOut; 
  114.   WriteOut('INLINE('); 
  115.  
  116.   While not EOF(InFile) do
  117.     begin 
  118.       Read(InFile, B); 
  119.       D1 := B div 16;
  120.       D2 := B mod 16; 
  121.       if EOF(InFile) then C := ')' else C := '/';
  122.       WriteOut('$' + HexTable[D1] + HexTable[D2] + C) 
  123.     end; 
  124.  
  125.   WriteOut(';');
  126.   WriteLnOut;
  127.  
  128.   Close(OutFile);
  129.   Close(InFile)
  130. end.
  131.